/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package alcatelparser.tags;

import alcatelparser.modules.AlgoUtil;
import alcatelparser.modules.BuilderFactory;
import alcatelparser.modules.Env;
import alcatelparser.modules.I;

/**
 *
 * @author geniuz
 */
public class StartTimeStampTag extends DefaultParserTag
{

    public StartTimeStampTag()
    {
    }
    private String value;
    public final void parseTag(int ai[], int i)
    {
        value = "";
        setStandartLength(ai, i);
        _array = ai;
        _startParsePosition = i;
        if(Env.getEnv().isFullForm())
        {
            BuilderFactory.getBuilder().writeTagContent(3, 0, getTagPropertiesValue(I.I(7043)), getTagIdentifyContent(i, i + 1));
            setTimeContent(i + 2);
        } else
        {
            switchTimeContent(i + 2);
        }
    }
    public String GetResult(){
        return value;
    }

    private void switchTimeContent(int i)
    {
        int j = _array[i];
        int k = calculateInnerTagType(j);
        if(isTagChecked(k))
        {
            String s = "";
            if(Env.getEnv().isFieldsDecoding())
                s = getDate(i + 2);
            else
                s = getHexStringContent(i + 2, AlgoUtil.getLength(_array, i + 1));
            BuilderFactory.getBuilder().writeTagContent(1, 4, getReducedTagPropertiesValue((new StringBuilder()).append(I.I(7011)).append(k).toString()), (new StringBuilder()).append("").append(s).toString());
            if(Env.getEnv().isFieldsDecoding())
                BuilderFactory.getBuilder().writeTagContent(1, 5, "", getTime(i + 5, true));
        }
    }

    private boolean isTagChecked(int i)
    {
        switch(i)
        {
        case 0: // '\0'
            return isTagChecked(I.I(1402));

        case 1: // '\001'
            return isTagChecked(I.I(1426));

        case 2: // '\002'
            return isTagChecked(I.I(1451));

        case 3: // '\003'
            return isTagChecked(I.I(1476));
        }
        return false;
    }

    private void setTimeContent(int i)
    {
        
        int j = _array[i];
        int k = calculateInnerTagType(j);
        String s = getTagPropertiesValue((new StringBuilder()).append(I.I(7011)).append(k).toString());
        String s1 = (new StringBuilder()).append(getTagIdentifyContent(i, i + 1)).append(getHexStringContent(i + 2, AlgoUtil.getLength(_array, i + 1))).toString();
        BuilderFactory.getBuilder().writeTagContent(4, 0, s, s1);
        String p1=getDate(i + 2),p2=getTime(i + 5, false);
        value = p1 +" "+ p2.replace('.', ':').substring(0,p2.length()-3) + "~";//s + " - " + 
        BuilderFactory.getBuilder().writeTagContent(9, 1, "", (new StringBuilder()).append(I.I(7023)).append(p1).toString());
        BuilderFactory.getBuilder().writeTagContent(9, 1, "", (new StringBuilder()).append(I.I(7033)).append(p2).toString());
        
    }

    public final String getParseIdentityTag()
    {
        return I.I(5392);
    }

    public final boolean isTagRequired()
    {
        return true;
    }
}
